package main

import (
	"embed"
	"log"
	"net/http"

	"github.com/keepfoo/minirest/handler"
	"github.com/keepfoo/minirest/logger"
)

//go:embed web
var webFS embed.FS

func main() {
	http.HandleFunc("/head", handler.HeadHandler)
	http.HandleFunc("/get", handler.GetHandler())
	http.HandleFunc("/get/", handler.TableGetHandler)
	http.HandleFunc("/post", handler.PostHandler)
	http.HandleFunc("/put", handler.PutHandler)
	http.HandleFunc("/delete", handler.DeleteHandler)
	http.HandleFunc("/login", handler.LoginHandler)

	http.Handle("/", http.FileServer(http.FS(webFS)))

	addr := ":9527"
	logger.SetLevel(logger.DEBUG)
	logger.Info("server listen on " + addr)
	err := http.ListenAndServe(addr, nil)
	if err != nil {
		log.Fatal(err)
	}
}
